import { ElMessage, ElMessageBox } from 'element-plus'

interface MessageImplements {
  info(title: string): void
  warning(title: string): void
  success(title: string): void
  error(title: string): void
}

export function useMessage() {
  class MessageClass implements MessageImplements {
    // 普通提示
    info(title: string): void {
      ElMessage.info(title)
    }

    // 警告提示
    warning(title: string): void {
      ElMessage.warning(title)
    }

    // 成功提示
    success(title: string): void {
      ElMessage.success(title)
    }

    // 错误提示
    error(title: string): void {
      ElMessage.error(title)
    }
  }

  return new MessageClass()
}

export function useMessageBox() {
  class MessageBoxClass implements MessageImplements {
    // 普通提示
    info(msg: string): void {
      ElMessageBox.alert(msg, 'message.box.title', {draggable: true,})
    }

    // 警告提示
    warning(msg: string): void {
      ElMessageBox.alert(msg, 'message.box.title', { type: 'warning', draggable: true, })
    }

    // 成功提示
    success(msg: string): void {
      ElMessageBox.alert(msg, 'message.box.title', { type: 'success', draggable: true, })
    }

    // 错误提示
    error(msg: string): void {
      ElMessageBox.alert(msg, 'message.box.title', { type: 'error', draggable: true, })
    }

    // 确认窗体
    confirm(msg: string, title: string = '提示') {
      return ElMessageBox.confirm(msg, title, {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning',
        draggable: true,
        closeOnClickModal: false
      })
    }
    // 提交内容
    prompt(msg: string, title: string = '提示') {
      return ElMessageBox.prompt(msg, title, {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning',
        draggable: true,
        closeOnClickModal: false
      })
    }
  }

  return new MessageBoxClass()
}
